#include "mobilefilelistitem.h"

#include <QFont>
#include <QDebug>
#include "systemfontsize.h"

const int ITEM_ICON_WIDTH = 48;
const int ITEM_ICON_HEIGHT = 48;

MobileFileListItem::MobileFileListItem(QPushButton *parent) : QPushButton(parent)
{
    initWidget();
    initConnect();
}

MobileFileListItem::~MobileFileListItem() {}

void MobileFileListItem::initWidget()
{
    //    setMinimumSize(170, 68);

    QHBoxLayout *mainHLayout = new QHBoxLayout();

    QVBoxLayout *labelVLayout = new QVBoxLayout();
    //项按钮
    m_itemIconLabel = new QLabel(this);
    m_itemIconLabel->setFixedSize(ITEM_ICON_WIDTH, ITEM_ICON_HEIGHT);
    //项名称
    m_itemNameLabel = new QLabel(this);

    QFont font;
    font.setBold(true);
    m_itemNameLabel->setFont(font);
    //每一项总数
    m_itemCountLabel = new QLabel(this);
    //初始时设置字号
    SystemFontSize::getInstance()->getSystemFontSize();
    QFont font12;
    font12 = SystemFontSize::getInstance()->getFontSize12px();
    m_itemCountLabel->setFont(font12);
    m_itemCountLabel->setStyleSheet("color:#8F9399;");

    labelVLayout->addStretch();
    labelVLayout->addWidget(m_itemNameLabel);
    labelVLayout->addWidget(m_itemCountLabel);
    labelVLayout->addStretch();

    mainHLayout->addSpacing(16);
    mainHLayout->addWidget(m_itemIconLabel);
    mainHLayout->addSpacing(10);
    mainHLayout->addLayout(labelVLayout);
    mainHLayout->addStretch();
    mainHLayout->setSpacing(0);
    mainHLayout->setMargin(0);
    setLayout(mainHLayout);

    this->setProperty("useButtonPalette", true);
}

void MobileFileListItem::initConnect()
{
    connect(SystemFontSize::getInstance(), &SystemFontSize::signalChangeFontSize, this, [=]() {
        QFont font12 = SystemFontSize::getInstance()->getFontSize12px();
        m_itemCountLabel->setFont(font12);
    });
}

//设置项按钮
void MobileFileListItem::setItemIcon(QString path)
{
    m_itemIconLabel->setPixmap(QIcon(path).pixmap(48, 48));
}

//设置项名称
void MobileFileListItem::setItemName(QString name)
{
    m_itemNameLabel->setText(name);
}

//设置项总数
void MobileFileListItem::setItemCount(int count)
{
    QString countItem = QString("%1 ").arg(count) + QString(tr("items")); // items项
    m_itemCountLabel->setText(countItem);
}

//设置所有文件label样式
void MobileFileListItem::setAllFile(QString file)
{
    QString allFile = QString("%1").arg(file);
    m_itemCountLabel->setText(allFile);
}
